import {Body, Controller, Get, HttpStatus, Post, Query, Res} from '@nestjs/common';
import {Response} from 'express';
import {CommonResponseDto} from '../dto/common.response.dto';
import {ResCode, UserStatus} from '../common/constants';
import {RecordListService} from '../service/record.list.service';



@Controller('api/record')
export class RecordListController {
    constructor(private readonly recordListService: RecordListService) {}

    @Post('/query-list')
    async getListByConditions(@Body() params: {userId: string, startDate: string, endDate: string, model: string}, @Res({ passthrough: true }) res: Response) {
        res.status(HttpStatus.OK);
        if (!params.userId) {
            return new CommonResponseDto(ResCode.ERROR, 'userId缺失')
        }
        try {
            const data = await this.recordListService.getUserRecordListByCondition(params.userId, params.startDate, params.endDate, params.model)
            return new CommonResponseDto(ResCode.OK, 'success', data)
        } catch(e){
            return new CommonResponseDto(ResCode.ERROR, '获取数据异常')
        }
    }


}
